package com.bestom.t9mod.broadcastreceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.bestom.t9mod.core.api.PowerApi;

/**
 * @author ..
 * */

public class StartReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        //此处及是重启的之后，打开我们app的方法
        String action = intent.getAction();
        /*if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
            Intent intentService= new Intent(context, SerialPortService.class);
            // 非常重要，如果缺少的话，程序将在启动时报错
            intentService.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //自启动服务（Service）
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                context.startForegroundService(new Intent(context, SerialPortService.class));
            } else {
                context.startService(new Intent(context, SerialPortService.class));
            }
        }else if (Intent.ACTION_SHUTDOWN.equals(action)) {
            new PowerApi().closeAllPower();
            new PowerApi().closeBoardPower();
        }*/

        String isReboot = intent.getStringExtra("isReboot");
        if (Intent.ACTION_SHUTDOWN.equals(action)) {
            Log.d("StartReceiver","收到关机或重启命令!--"+isReboot);
            if(!(isReboot != null && isReboot.equals("1"))) {
                new PowerApi().closeAllPower();
                new PowerApi().closeBoardPower();
            }
        }
    }
}
